<template>
	<view class="updateGroup">
		<view class="box" v-for="(item,index) in tempFilePaths" :key="index" >
			<image :src="item" mode="aspectFill"></image>
			<view class="close" @click="colseImage(index)">
				×
			</view>
		</view>
		<view class="box add" @click="choseImage()" v-show="tempFilePaths.length<maxSize">+</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tempFilePaths : [],
				maxSize:9
			};
		},
		methods:{
			// 关闭图片
			colseImage(e){
				console.log(e)
				this.tempFilePaths.splice(e); // 移除数组索引下元素
			},
			// 选择本地图片
			choseImage(){
				uni.chooseImage({
					success:res=>{
						let oldTems = this.tempFilePaths;
						let newTems = [...oldTems,...res.tempFilePaths]
						newTems = newTems.slice(0,this.maxSize); // 保留数组0-9索引下的元素
						this.tempFilePaths = newTems;
					}
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
.updateGroup{
	padding: 30rpx;
	display: flex;
	flex-wrap: wrap; // 换行
	.box{
		margin-right: 15rpx;
		margin-bottom: 15rpx;
		width: 100rpx;
		height: 100rpx;
		background: #eee;
		position: relative;
		image{
			width: 100%;
			height: 100%;
		}
		.close{
			position: absolute;
			top:0;
			right: 0;
			width: 30rpx;
			height: 30rpx;
			background: rgba(0, 0, 0, 0.7);
			color:#fff;
			border-radius: 0 0 0 80rpx;
			display: flex;
			justify-content: center;
			align-items: center;
		}
	}
	
	.add{
		font-size: 80rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		color: #888;
	}
}
</style>
